package py.edu.ucom.cadira.game.event.war;

import org.jdom.Document;
import org.jdom.Element;

import py.edu.ucom.cadira.game.war.WarUser;

/**
 * @author largonet
 *
 */
public class UserRegistredEvent extends WarGameEvent {
    private WarUser user;
    public UserRegistredEvent(WarUser user) {
        this.user = user; 
    }
    public UserRegistredEvent() {
        
    }
    public String toString(){
        StringBuffer buff=new StringBuffer();
       buff.append(super.toString());
       buff.append("WarUser: "+user.toString()).append("");
        return buff.toString();
    }
	@Override
	public void fromXML(Document xml) {
		Element root = xml.getRootElement();
		Element userRegisteredNode = root.getChild("UserRegistredEvent");
		Element userNode = userRegisteredNode.getChild("usuario");
		user.fromXml(userNode);
	}
	@Override
	public void toXML(Element root) {
		Element userRegisteredNode = new Element("UserRegistredEvent");
		Element userNode = user.toXml();
		userRegisteredNode.addContent(userNode);
		
		root.addContent(userRegisteredNode);
	}
	public WarUser getUser() {
		return user;
	}
	public void setUser(WarUser user) {
		this.user = user;
	}
	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof UserRegistredEvent)) {
			return false;
		}
		UserRegistredEvent otherObj = (UserRegistredEvent) obj;
		if (otherObj.getUser().equals(getUser())) {
			return true;
		}
		return false;
	}
}
